package yal

import (
	"encoding/json"

	"gitee.com/mkwchecking/sr-core/yal/yconv"
)

var EmptyAny any = nil

func New(val any) *YVal {
	return &YVal{val: val}
}

type YVal struct {
	val any
}

func (s *YVal) Scan(output interface{}) error {
	switch v := s.val.(type) {
	case []byte:
		return json.Unmarshal(v, output)
	case string:
		return json.Unmarshal([]byte(v), output)
	default:
		return yconv.AnyToObj(v, output)
	}
}
